package com.cn.kehong.controller;


import com.cn.kehong.api.IPlanMothService;
import com.cn.kehong.api.IPlanYearService;
import com.cn.kehong.domain.PlanMoth;
import com.cn.kehong.domain.PlanMothVo;
import com.cn.kehong.domain.PlanYear;
import com.cn.kehong.utils.CommonUtil;
import com.cn.kehong.utils.JsonResponse;
import com.cn.kehong.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/planMoth")
public class PlanMothController {

    @Autowired
    private IPlanMothService planMothService;

    @RequestMapping("/getPlanMothList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PlanMoth>> getPlanMothList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<PlanMoth>> response = new JsonResponse<List<PlanMoth>>();
        List<PlanMoth> list  = planMothService.getPlanMothList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getPlanMothDayValue/{frontToken}")
    @ResponseBody
    public JsonResponse<String> getPlanMothDayValue(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result  = planMothService.getPlanMothDayValue(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getCurrentYearPlanMothList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PlanMothVo>> getCurrentYearPlanMothList(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<PlanMothVo>> response = new JsonResponse<List<PlanMothVo>>();
        List<PlanMothVo> list  = planMothService.getCurrentYearPlanMothList();
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getAllYearPlanMothList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<PlanMoth>> getAllYearPlanMothList(QueryForm queryForm,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<PlanMoth>> response = new JsonResponse<List<PlanMoth>>();
        List<PlanMoth> list  = planMothService.getAllYearPlanMothList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getCurrentPlanMoth/{frontToken}")
    @ResponseBody
    public JsonResponse<PlanMoth> getCurrentPlanMoth( @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<PlanMoth> response = new JsonResponse<PlanMoth>();
        PlanMoth planMoth  = planMothService.getCurrentPlanMoth();
        response.setResult(planMoth);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/addPlanMoth/{frontToken}")
    public JsonResponse<String> addPlanMoth(@RequestBody PlanMoth planMoth, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.addPlanMoth(planMoth);
        return CommonUtil.getResponseData(response,result);
    }


    @ResponseBody
    @RequestMapping("/updatePlanMoth/{frontToken}")
    public JsonResponse<String> updatePlanMoth(@RequestBody PlanMoth planMoth, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.updatePlanMoth(planMoth);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateCheckPlanMoth/{frontToken}")
    public JsonResponse<String> updateCheckPlanMoth(PlanMoth planMoth, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.updateCheckPlanMoth(planMoth);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updatePlanMothVersion/{frontToken}")
    public JsonResponse<String> updatePlanMothVersion(@RequestBody PlanMoth planMoth, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.updatePlanMothVersion(planMoth);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/deletePlanMothById/{frontToken}")
    public JsonResponse<String> deletePlanMothById(String id, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.deletePlanMothById(id);
        return CommonUtil.getResponseData(response,result);
    }


    @RequestMapping("/getCheckPlanMothCount/{frontToken}")
    @ResponseBody
    public JsonResponse<Integer> getCheckPlanMothCount(@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<Integer> response = new JsonResponse<Integer>();
        Integer count  = planMothService.getCheckPlanMothCount();
        response.setResult(count);
        response.setSuccess(true);
        return  response;
    }


    @ResponseBody
    @RequestMapping("/isHavingMoth/{frontToken}")
    public JsonResponse<String> isHavingMoth(String month, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = planMothService.isHavingMoth(month);
        return CommonUtil.getResponseData(response,result);
    }
}
